package com.jyxd.web.mq;

import com.jyxd.web.data.basic.NursingTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class NursingTaskSender {

    private final Logger logger = LoggerFactory.getLogger(NursingTaskSender.class);
    private final AmqpTemplate rabbitTemplate;

    @Value("${icu.job.mq.nurse.delay.routingKey}")
    private String routingKey;
    @Value("${icu.job.mq.nurse.delay.exchange}")
    private String exchange;

    public NursingTaskSender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void send(NursingTask nursingTask, final long delay) {
        rabbitTemplate.convertAndSend(exchange, routingKey, nursingTask, message -> {
            message.getMessageProperties().setHeader(MessageProperties.X_DELAY, delay);
            return message;
        });
    }

}